import grails.test.*

class VolunteerControllerTests extends GrailsUnitTestCase {
    Volunteer volunteer
    VolunteerController vc

    protected void setUp() {
        // save a Volunteer:
        volunteer = new Volunteer(firstName:"Elmer", lastName:"Fudd", email:"elmerfudd@warnerbros.com", password:"ef")
        volunteer.save()

        // setup the volunteer controller:
        vc = new VolunteerController()
    }

    protected void tearDown() {
        volunteer.delete()
    }

    /**
    * Test the UserController.handleLogin action.
    *
    * If the login succeeds, it will put the volunteer object into the session.
    */
    void testHandleLogin() {

      // Setup controller parameters
      vc.params.email = volunteer.email

      // Call the action
      vc.handleLogin()

      // If action functioned correctly, it put a volunteer object
      // into the session
      def sessUser = vc.session.volunteer
      assert sessUser
      assertEquals("Expected ids to match", volunteer.id, sessUser.id)
      // And the volunteer was redirected to the Event List page
      assertEquals "/event", vc.response.redirectedUrl
    }

    /**
    * Test the UserController.handleLogin action.
    *
    * If the login fails, it will redirect to login and set a flash message.
    */
      void testHandleLoginInvalidUser() {
      // Setup controller parameters
      vc.params.userName = "INVALID_USER_NAME"

      // Call the action
      vc.handleLogin()
      assertEquals "/volunteer/login", vc.response.redirectedUrl
      def message = vc.flash.message
      assert message
      assert message.startsWith("User not found")
    }

    /**
    * Test the UserController.login action
    *
    * If the logout action succeeds, it will remove the volunteer object from
    * the session.
    */
    void testLogout() {
      // make it look like volunteer is logged in
      vc.session.volunteer = volunteer

      vc.logout()
      def sessUser = vc.session.volunteer
      assertNull("Expected session volunteer to be null", sessUser)
      assertEquals "/volunteer/login", vc.response.redirectedUrl
    }

  public Object invokeMethod(String s, Object o) {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
  }

  public Object getProperty(String s) {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
  }

  public void setProperty(String s, Object o) {
    //To change body of implemented methods use File | Settings | File Templates.
  }

  public MetaClass getMetaClass() {
    return null;  //To change body of implemented methods use File | Settings | File Templates.
  }

  public void setMetaClass(MetaClass metaClass) {
    //To change body of implemented methods use File | Settings | File Templates.
  }
}
